\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{float}
\usepackage{bm}
\title{Test Report}
\author{3190101820 Weizhen Li}
\date{2021-10-28}
\lstset{numbers=left,basicstyle=\footnotesize,showstringspaces=false,otherkeywords={string},language = C++}
\geometry{left=2.5cm,right=2cm,top=2.5cm,bottom=2.5cm}
\begin{document}
\maketitle
\paragraph{1 Testing functions in class Polynomial}
~
\begin{lstlisting}[frame=shadowbox]
 //testing the class Polynomial
 cout<<"testing the class Polynomial!"<<endl;
 vector<double> arr(3,1);
 Polynomial p1(2,arr);
 cout<<"polynomial p1: "<<p1<<endl;
 Polynomial p2(2,arr);
 cout<<"polynomial p2: "<<p2<<endl;
 cout<<"the derivative of p1: "<<p1.get_deri()<<endl;
 cout<<"the value of p1 at x=2: "<<p1.get_value(2)<<endl;
 cout<<"the value of p1' at x=1: "<<p1.get_deri_value(1)<<endl;
 cout<<"p1+p2: "<<p1+p2<<endl;
 cout<<"p1-p2: "<<p1-p2<<endl;
 cout<<"p1*p2: "<<p1*p2<<endl;
\end{lstlisting}
We construct two polynomials p1 and p2,where $p_{1}=x^{2}+x+1$ and $p_{2}=x^{2}+x+1$.It's easy to get $p_{1}'=2x+1,p_{1}(2)=7,p_{1}'(1)=3$ and
$p_{1}+p_{2}=2x^{2}+2x+2,p_{1}-p_{2}=0,p_{1}*p_{2}=x^{4}+2x^{3}+3x^{2}+2x+1$.Note that we have made use of the function of a number multiplying a 
polynomial when implementing polynomial subtraction.The actual results are consistent with the program running results which are shown below.\\
\begin{lstlisting}[frame=shadowbox]
testing the class Polynomial!
polynomial p1: x^2+x+1
polynomial p2: x^2+x+1
the derivative of p1: 2x+1
the value of p1 at x=2: 7
the value of p1' at x=1: 3
p1+p2: 2x^2+2x+2
p1-p2: 0
p1*p2: x^4+2x^3+3x^2+2x+1
\end{lstlisting}


\paragraph{2 Testing functions in class InterConditions}
~
\begin{lstlisting}[frame=shadowbox]
//testing the class InterConditions
cout<<"testing the class InterConditions!"<<endl;
int n=3;
vector<double> _X = {0,1,3};
vector<double> _f = {1,2,0};
vector<double> _m = {0,1,1};
vector<vector<double> > _df(n,vector<double>(1));
_df[0][0]=0;_df[1][0]=-1;_df[2][0]=0;
InterConditions Q(n,_X,_f,_m,_df);
cout<<"the divided difference table of datas you input(exercise 6 in the homework!):"<<endl;
vector<double> X_=Q.get_X();
vector<vector<double> > arry=Q.output_difftable();
for(int i=0;i<arry.size();i++)
{
cout<<X_[i]<<" ";
for(int j=0;j<=i;j++)
cout<<arry[i][j]<<" ";
cout<<endl;
}
\end{lstlisting}
Here we construct an object of the class to test its practicability.We only test the function which 
outputs the divided difference table because all other public functions are applied in it.Here the data
 is just the same as Exercise Six in our homework. Computing it by hand,results are consistent with the program
 running results which are shown below.\\
\begin{lstlisting}[frame=shadowbox]
testing the class InterConditions!
the divided difference table of datas you input(exercise 6 in the homework!):
0 1 
1 2 1 
1 2 -1 -2 
3 0 -1 0 0.666667 
3 0 0 0.5 0.25 -0.138889 
\end{lstlisting}



\paragraph{3 Testing functions in class NewtonInterp}
\subparagraph{3.1 Testing Method One}
~
\begin{lstlisting}[frame=shadowbox]
cout<<"testing the class NewtonInterp!"<<endl;
cout<<"testing Method One!"<<endl;
NewtonInterp P(Q);
P.Interpolation_Method1();
Polynomial P3=P.get_interPoly_();
cout<<"the interpolation polynomial of datas you input: "<<endl;
cout<<P3<<endl;
cout<<"the value of the interpolation polynomial at x=2: "<<P3.get_value(2)<<endl;
\end{lstlisting}
Here we construct an object by using the interpolation conditions in Exercise Six in our homework i.e. the data in testing class InterConditions.
In our homework,the interpolation polynomial is $-0.1389x^{4}+1.3611x^{3}-4.3056x^{2}+4.0833x+1$,computing by hand.
And estimate the value at $x=2$ is $\frac{11}{18},i.e. 0.6111$.The results are consistent with program running results which are shown below.\\ 
\begin{lstlisting}[frame=shadowbox]
testing the class NewtonInterp!
testing Method One!
the interpolation polynomial of datas you input: 
-0.138889x^4+1.36111x^3-4.30556x^2+4.08333x+1
the value of the interpolation polynomial at x=2: 0.611111
\end{lstlisting}
\subparagraph{3.2 Testing Method Two}
~
\begin{lstlisting}[frame=shadowbox]
//testing Method Two
cout<<"\n"<<"testing Method Two!"<<endl;
vector<double> _X1 = {0,1};
vector<double> _f1 = {1,2};
vector<double> _m1 = {0,1};
vector<vector<double> > _df1(2,vector<double>(1));
_df1[0][0]=0;_df1[1][0]=-1;
InterConditions Q1(2,_X1,_f1,_m1,_df1);
NewtonInterp P1(Q1);
P1.Interpolation_Method1();
cout<<"the interpolation polynomial of current datas:"<<endl;
cout<<P1.get_interPoly_()<<endl;
vector<double> New_X = {3};
vector<double> New_f = {0};
vector<double> New_m = {1};
vector<vector<double> > New_df(1,vector<double>(1));
New_df[0][0]=0;
P1.Interpolation_Method2(New_X,New_f,New_m,New_df);
cout<<"new interpolation polynomial after you newly add datas:"<<endl;
cout<<P1.get_interPoly_()<<endl;
\end{lstlisting}
Here we also use the same data as Exercise Six in our homework but divide it into two parts to test Method Two.
Computing by hand,in the first part before adding new data,the interpolation polynomial is $-2x^{2}+3x+1$.And when adding
 new data,the result is the same as the last test of Method One,i.e. $-0.1389x^{4}+1.3611x^{3}-4.3056x^{2}+4.0833x+1$, which 
 is consistent with the result applying Method Two as below.\\
\begin{lstlisting}[frame=shadowbox]
testing Method Two!
the interpolation polynomial of current datas:
-2x^2+3x+1
new interpolation polynomial after you newly add datas:
-0.138889x^4+1.36111x^3-4.30556x^2+4.08333x+1
\end{lstlisting}
\subparagraph{3.3 Testing Neville-Aitken algorithm}
~
\begin{lstlisting}[frame=shadowbox]
 //testing static Neville-Aitken algorithm,namely example 3.30 in notes
 cout<<"testing static Neville-Aitken algorithm,namely example 3.30 in notes!"<<endl;
 vector<double> _X_ = {0,1,2,3};
 vector<double> _f_ = {6,-3,-6,9};
 InterConditions QQ(4,_X_,_f_);
 cout<<"its value at x=1.5 by Neville-Aitken algorithm: "
 <<NewtonInterp::Neville_Aitken(QQ,1.5)<<endl;
\end{lstlisting}
Here we use the same data of Example 3.30 in notes.The answer -6 is consistent with program running result which is shown below.
\begin{lstlisting}[frame=shadowbox]
testing static Neville-Aitken algorithm,namely example 3.30 in notes!
its value at x=1.5 by Neville-Aitken algorithm: -6
\end{lstlisting}

\end{document}